//
//  ZCBaiduControllerView.m
//  03地图定位
//
//  Created by 张聪 on 16/7/24.
//  Copyright © 2016年 张聪. All rights reserved.
//

#import "ZCBaiduControllerView.h"
#import "Masonry.h"
#import "ZCSerchViewController.h"

@implementation ZCBaiduControllerView

- (instancetype)initWithFrame:(CGRect)frame {
    
    if (self = [super initWithFrame:frame]) {
        
        self.backgroundColor = [UIColor grayColor];
        
        //切换地图
        NSArray *segmentes = [[NSArray alloc] initWithObjects:@"1",@"2",@"3", nil];
        
        UISegmentedControl *segmenteControl = [[UISegmentedControl alloc] initWithItems:segmentes];
        self.segmenteControl = segmenteControl;
        
        [self addSubview:self.segmenteControl];
        
        [self.segmenteControl addTarget:self action:@selector(didSegmenteClick:) forControlEvents:UIControlEventValueChanged];
        self.segmenteControl.selectedSegmentIndex = 0;
        
        //定位返回
        UIButton *blackBtn = [[UIButton alloc] init];
        self.blackBtn = blackBtn;
        blackBtn.backgroundColor = [UIColor orangeColor];
        blackBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [blackBtn setTitle:@"定位返回" forState:UIControlStateNormal];
        [self addSubview:blackBtn];
        
        [self.blackBtn addTarget:self action:@selector(didBlackClick) forControlEvents:UIControlEventTouchUpInside];
        
        
        //检索按钮
        UIButton *serchBtn = [[UIButton alloc] init];
        serchBtn.backgroundColor = [UIColor orangeColor];
        serchBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [serchBtn setTitle:@"兴趣搜索" forState:UIControlStateNormal];
        self.serchBtn = serchBtn;
        [self addSubview:serchBtn];
        [self.serchBtn addTarget:self action:@selector(didSerchBtnClick) forControlEvents:UIControlEventTouchUpInside];
        
        UIButton *routeBtn = [[UIButton alloc] init];
        routeBtn.backgroundColor = [UIColor orangeColor];
        self.routeBtn = routeBtn;
        routeBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [routeBtn setTitle:@"线路规划" forState:UIControlStateNormal];
        [routeBtn addTarget:self action:@selector(didRouteBtnClick) forControlEvents:UIControlEventTouchUpInside];
        [self addSubview:routeBtn];
        
        UIButton *hotMapBtn = [[UIButton alloc] init];
        self.hotMapBtn = hotMapBtn;
        hotMapBtn.backgroundColor = [UIColor orangeColor];
        hotMapBtn.titleLabel.font = [UIFont systemFontOfSize:13];
        [hotMapBtn setTitle:@"开启热力图" forState:UIControlStateNormal];
        [hotMapBtn addTarget:self action:@selector(didHotMaoBtnClick:) forControlEvents:UIControlEventTouchUpInside];
        
        [self addSubview:hotMapBtn];
        
        
    }
    return self;
}

#pragma mark - 设置子控件
- (void)layoutSubviews {
    [super layoutSubviews];
    
    [self.segmenteControl mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.leading.equalTo(self).offset(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.blackBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.segmenteControl.mas_bottom).offset(30);
        make.leading.equalTo(self).offset(20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.serchBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self).offset(20);
        make.trailing.equalTo(self).offset(-20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
        
    }];
    
    [self.routeBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.blackBtn.mas_top);
        make.trailing.equalTo(self).offset(-20);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    
    
    
    
    [self.hotMapBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self);
        make.width.mas_equalTo(80);
        make.height.mas_equalTo(30);
    }];
    

}

#pragma mark - 事件响应
//开启热力图
- (void)didHotMaoBtnClick:(UIButton *)sender {
    
    if ([self.BaiduControllerViewDelegate respondsToSelector:@selector(stratHotMap:)]) {
        [self.BaiduControllerViewDelegate stratHotMap:sender];
    }
    
    
}


//地图选择
- (void)didSegmenteClick:(UISegmentedControl *)sender {
    
    if ([self.BaiduControllerViewDelegate respondsToSelector:@selector(didMapChangeClick:)]) {
    
        [self.BaiduControllerViewDelegate didMapChangeClick:sender];
  
    }

}



//路径规划
- (void)didRouteBtnClick {
    NSLog(@"路径规划");
    
    if ([self.BaiduControllerViewDelegate respondsToSelector:@selector(didRouteClick)]) {
        [self.BaiduControllerViewDelegate didRouteClick];
    }
    
}

//定位返回
- (void)didBlackClick {
    
    if ([self.BaiduControllerViewDelegate respondsToSelector:@selector(againPosition)]) {
        [self.BaiduControllerViewDelegate againPosition];
    }
    
}

- (void)didSerchBtnClick {
    
    NSLog(@"兴趣搜索点击");
    
    //判断代理有没有实现代理方法
    if ([self.BaiduControllerViewDelegate respondsToSelector:@selector(pushSerchVc)]) {
        
        [self.BaiduControllerViewDelegate pushSerchVc];
    }
    

}

#pragma mark - 懒加载
- (UIButton *)routeBtn {
    if (_routeBtn == nil) {
        _routeBtn = [[UIButton alloc] init];
    }
    
    return _routeBtn;
}

- (UIButton *)serchBtn {
    
    if (_serchBtn == nil) {
        _serchBtn = [[UIButton alloc] init];
    }
    
    return _serchBtn;
    
    
}

- (UIButton *)blackBtn {
    if (_blackBtn == nil) {
        _blackBtn = [[UIButton alloc] init];
    }
    
    return _blackBtn;
    
}


- (UISegmentedControl *)segmenteControl {
    
    if (_segmenteControl == nil) {
        _segmenteControl = [[UISegmentedControl alloc] init];
        
        
    }
    
    return _segmenteControl;
}



@end
